<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Login Page</title>
    <link rel="icon" href="{{ url_for('static', filename='resources/title_login.png') }}" type="image/x-icon">
    <!-- 引入本地 Bootstrap CSS -->
    <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/bootstrap.min.css') }}">
    <!-- 引入本地 Bootstrap JavaScript 和依赖的 Popper.js -->
    <script src="{{ url_for('static', filename='js/popper.min.js') }}"></script>
    <script src="{{ url_for('static', filename='js/bootstrap.min.js') }}"></script>
    <!-- 引入自定义样式 -->
    <link rel="stylesheet"  type="text/css" href="{{ url_for('static', filename='css/form_group.css') }}">
    <style>
        body {
            background-color: #f8f9fa;
            background-image: url('static/resources/bg_login.png');
            background-repeat: no-repeat;
            background-attachment: fixed;
            background-size: cover;
            font-family: 'Roboto', sans-serif;
        }
        h1 {
            text-align: center;
            margin: 90px auto;
            color: #ffffff;
        }
        .login-container {
            max-width: 400px;
            margin: 60px auto;
            padding: 20px;
            /*background-color: #fff;*/
            border-radius: 0.5rem;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
        .login-header {
            text-align: center;
            margin-bottom: 30px;
        }
        .login-header h2 {
            color: #343a40;
        }
        /* 设置按钮组的布局 */
        .button-group {
            display: flex; /* 使用弹性布局 */
            gap: 10px; /* 按钮之间的间距 */
            justify-content: space-between; /* 按钮均匀分布 */
            width: 100%; /* 容器宽度占满父元素 */
        }
        /* 设置按钮的样式 */
        .btn {
            flex: 1; /* 让每个按钮自动扩展以填充可用空间 */
            margin: 0 5px; /* 左右留一点间距 */
            padding: 10px; /* 内边距 */
            font-size: 16px; /* 字体大小 */
            border: none; /* 去掉默认边框 */
            border-radius: 5px; /* 圆角 */
            cursor: pointer; /* 鼠标悬停时显示手型 */
            text-align: center; /* 文字居中对齐 */
        }
        /* 登录按钮样式 */
        .btn[value="login"] {
            background-color: #4CAF50; /* 绿色背景 */
            color: white; /* 白色文字 */
        }
        /* 注册按钮样式 */
        .btn[value="register"] {
            background-color: #008CBA; /* 蓝色背景 */
            color: white; /* 白色文字 */
        }
        
        @keyframes l6 {
            100% {inset:0}
        }
        /* 隐藏默认的对话框 */
        dialog {
            display: none;
        }
        /* 当对话框可见时显示 */
        dialog[open] {
            display: block;
            position: fixed;
            top: 55%;
            left: 20%;
            transform: translate(-50%, -50%);
            background-color: #fff;
            border: 1px solid #ccc;
            border-radius: 0.5rem;
            padding: 20px;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
            border-radius: 8px;
            width: 260px;
            max-width: 90%;
            z-index: 1000;
            flex-direction: column;
            align-items: center;
            text-align: center;
        }
        dialog p {
            font-family: Arial, sans-serif; /* 设置字体家族 */
            font-size: 14px; /* 设置字体大小 */
            font-weight: bold; /* 设置字体粗细 */
            font-style: normal; /* 设置字体样式 */
            margin: 0 0 15px;
        }
        dialog button[value='error'] {
            background-color: #e74c3c;
            color: white;
            border: none;
            padding: 6px 12px;
            border-radius: 6px;
            cursor: pointer;
        }
        dialog button[value='success'] {
            background-color: #008CBA;
            color: white;
            border: none;
            padding: 6px 12px;
            border-radius: 6px;
            cursor: pointer;
        }
        dialog button:hover[value='error'] {
            background-color: #c0392b;
        }
        dialog button:hover[value='success'] {
            background-color: #4CAF50;
        }
    </style>
</head>
<body>
    <h1>图书管理系统</h1>
    <div class="login-container">
        <div class="login-header">
            <!-- <div class="loader"></div> -->
            <h2>登录账户</h2>
        </div>
        <form action="{{ url_for('login') }}" method="POST" id="login_form">
            <div class="form-group">
                <label for="username">用户名</label>
                <input type="text" id="username" name="username" placeholder="输入用户名" required>
            </div>
            
            <div class="form-group">
                <label for="password">密码</label>
                <input type="password" id="password" name="password" placeholder="输入密码" required>
            </div>
            
            <div class="button-group">
                <button type="button" class="btn" value="login" onclick="submitForm('login')">登录</button>
                <button type="button" class="btn" value="register" onclick="submitForm('register')">注册</button>
            </div>
        </form>
        {%- if error_message %}
        <dialog open>
            <p>{{ error_message }}</p>
            <button value="error" onclick="this.parentNode.close()">关闭</button>
        </dialog>
        {%- endif %}
        {%- if success_message %}
        <dialog open>
            <p>{{ success_message }}</p>
            <button value="success" onclick="this.parentNode.close()">关闭</button>
        </dialog>
        {%- endif %}
    </div>
</body>


<script>
    function submitForm(action) {
        const form = document.getElementById('login_form');
        const hiddenInput = document.createElement('input');
        hiddenInput.type = 'hidden';
        hiddenInput.name = 'action';
        hiddenInput.value = action;
        form.appendChild(hiddenInput);
        form.submit();
    }
</script>


</html>